package cn.chenxiejia;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: Task2
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/11 14:44
 */
public class Task2 {
    public static void main(String[] args) {
        List<Book> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Book("Web前端" + i, i * 10, "author" + i));
        }
        System.out.println("请输入书名：");
        Scanner sc = new Scanner(System.in);
        if (sc.hasNext()) {
            var name = sc.next();
            for (int i = 0; i < 10; i++) {
                if (name.equals(list.get(i).getName())) {
                    System.out.println(list.get(i));
                }
            }
        } else {
            System.out.println("输入不合法");
        }
    }
}

@NoArgsConstructor
@Data
@AllArgsConstructor
class Book {
    private String name;
    private int price;
    private String author;

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", author='" + author + '\'' +
                '}';
    }
}
